import {
    createBtnHandler
} from './create';
import {
    editBtnHandler
} from './edit';
import {
    removeBtnHandler
} from './remove';
import {
    grid
} from '../common/grid';
import {
    editPwd,loginOut
} from '../common/settings';

$(function () {

    grid();
    window.editPwd=editPwd;
    window.loginOut=loginOut;

    let $table = $('#table').bootstrapTable({
        toolbar: '#toolbar',
        url: GLOBAL_articleListUrl,
        sidePagination: "server",
        queryParamsType: '',
        queryParams: function (params) {
            let query = $.extend({}, params,{cat_id:GLOBAL_cateid});
            return query;

        },

        columns: [{
            checkbox: true
        }, {
            field: 'cat_name',
            title: '中/英文分类名',
            sortable: true,
            formatter: function (value, row, index) {
                return row.cat_name_zh+" || "+row.cat_name_en;
            },
        },  {
            field: 'title_zh',
            title: '中文标题',
            sortable: true
        }, {
            field: 'title_en',
            title: '英文标题',
            sortable: true
        }, {
            field: 'sort',
            title: '排序',
            sortable: true
        },{
            field: 'update_time',
            title: '更新时间',
            sortable: true
        }]
    });


    window.createBtnHandler = createBtnHandler;
    window.editBtnHandler = editBtnHandler;
    window.removeBtnHandler = removeBtnHandler;

    //多选不能编辑
    $table.on('check.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
    });
    $table.on('uncheck.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
    });
    $table.on('check-all.bs.table', (rows) => {
        $('#editBtn').attr('disabled', 'disabled');
    });
    $table.on('uncheck-all.bs.table', (rows) => {
        $('#editBtn').removeAttr('disabled');
    });



});